/*
 * nodes.h
 *
 *  Created on: Jan 15, 2014
 *      Author: univ3rse
 */

#ifndef NODES_H_
#define NODES_H_

#include "bjm.h"

typedef struct exp *expTree;
typedef enum {
	ADD, SUB, MUL, DIV, ASI, INC, DEC, FCT
} oType;
typedef enum {
	lt, gt, eq, ne, ge, le
} reloType;
typedef enum {
	IN, FN
} conType;
typedef enum {
and, or
}boolType;
typedef enum {
oExp, cExp, vExp, rExp, bExp, ifExp, prExp, loopExp,multiExp
} expType;
typedef enum {
ifSt, elseSt
} ifType;
typedef enum {
whileLoop, untilLoop
} loopType;

struct exp {
expType expKind;
union {
	struct {
		oType op;
		expTree left;
		expTree right;
	} oper;

	struct {
		reloType op;
		expTree left;
		expTree right;
	} relo;

	struct {
		reloType op;
		expTree left;
		expTree right;
	} boolo;

	struct {
		float constVal;
		conType ds;
	} val;

	struct {
		ifType it;
		expTree relEx;
		expTree ifSt;
		expTree elseSt;
	} ifs;

	struct {
		loopType lp;
		expTree relEx;
		expTree loopSt;
	} loops;

	struct {
			expTree left;
			expTree right;
		} multi;

	struct {
		expTree toPrint;
	} print;
	char *var;

} uni;
};

void startScope();
void endScope();

expTree opExp(oType op, expTree left, expTree right);
expTree idExp(char *var);
expTree conExp(conType ds, int constVal);
expTree relopExp(reloType relop, expTree left, expTree right);
expTree boolExp(boolType boolop, expTree left, expTree right);
expTree ifsExp(ifType it, expTree relEx, expTree ifSt, expTree elseSt);
expTree loopsExp(loopType lp, expTree relEx, expTree loopSt);
expTree printExp(expTree toPrint);
expTree multiStmt(expTree left, expTree right);
data_t ex(expTree eT);

#endif /* NODES_H_ */
